﻿package _3_Panel;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
/**
 * 2011-6-1 23:55:57
 * @author Administrator
 */
public class TJInternalFrame {
    JFrame frame;
    Container contentPane;
    JDesktopPane desktopPane;
    JInternalFrame interFrame1,interFrame2,interFrame3;
    public TJInternalFrame(){
        frame=new JFrame();
        contentPane=frame.getContentPane();
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        desktopPane=new JDesktopPane();
        desktopPane.setLayout(new GridBagLayout());
        contentPane.add(desktopPane);
        interFrame1=new JInternalFrame("第一个窗口", true, true, true, true);
        interFrame1.setPreferredSize(new Dimension(300,300));        
        interFrame1.setVisible(true);
//        interFrame1.addComponentListener(new ComponentAdapter(){
//
//            @Override
//            public void componentMoved(ComponentEvent e) {
//                desktopPane.updateUI();
//            }
//
//        });
        add(desktopPane, interFrame1, 0, 0, 1, 1, 1, 1);
        interFrame2=new JInternalFrame("第二个窗口", true, true, true, true);
        interFrame2.setPreferredSize(new Dimension(300,300));
        interFrame2.setVisible(true);
        add(desktopPane, interFrame2, 0, 1, 1, 1, 1, 1);
        interFrame3=new JInternalFrame("第三个窗口", true, true, true, true);
        interFrame3.setPreferredSize(new Dimension(300,600));
        interFrame3.setVisible(true);
        add(desktopPane, interFrame3, 1, 0, 1, 2, 1, 1);
        frame.setVisible(true);
    }
    public void add(Container main,Container child,int gridx,int gridy,int gridWidth,int gridHeight,double weightx,double weighty){
        GridBagConstraints c=new GridBagConstraints();
        c.gridx=gridx;
        c.gridy=gridy;
        c.gridwidth=gridWidth;
        c.gridheight=gridHeight;
        c.weightx=weightx;
        c.weighty=weighty;
        c.fill=GridBagConstraints.BOTH;
        main.add(child,c);
    }
    public static void main(String args[]){
        new TJInternalFrame();
    }
}
